package entity.base;

import java.io.Serializable;
import java.util.Date;
import java.util.UUID;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;

@MappedSuperclass
public abstract class BaseEntity implements Serializable, Cloneable {
	
	private static final long	serialVersionUID	= 6844263640949948295L;
	
	@Id
	@Column(name = "ID", nullable = false, length = 36)
	private String				id;
	
	@Column(name = "DELETED", nullable = false)
	private boolean				deleted				= false;
	
	@Column(name = "LAST_SAVE_DATE")
	private Date				lastSaveDate;
	
	@PrePersist
	public void prePersist() {
		id = UUID.randomUUID().toString();
		lastSaveDate = new Date();
	}
	
	@PreUpdate
	public void preUpdate() {
		lastSaveDate = new Date();
	}
	
	public boolean isDeleted() {
		return deleted;
	}
	
	public void setDeleted(boolean deleted) {
		this.deleted = deleted;
	}
	
	public String getId() {
		return id;
	}
	
	public void setId(String id) {
		this.id = id;
	}
	
	public Date getLastSaveDate() {
		return lastSaveDate;
	}
	
	public void setLastSaveDate(Date lastSaveDate) {
		this.lastSaveDate = lastSaveDate;
	}
	
	@Override
	public abstract String toString();
}
